﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 图书管理系统
{
    public partial class RegisterBaseForm : Form
    {
        public RegisterBaseForm()
        {
            InitializeComponent();
        }

        private void Registerbutton_Click(object sender, EventArgs e)
        {
            string name = this.NametextBox.Text.Trim();
            string id = this.UidtextBox.Text.Trim();
            string pwd = this.PwdtextBox.Text.Trim();
            string sex = this.SexcomboBox.Text.Trim();
            string collage = this.CollagecomboBox.Text.Trim();
            string power = this.PowercomboBox.Text.Trim();
            string strsql = "insert into MemberInfo(name, uid, pwd, sex, collage, power, facepath)" +
                        " values('" + name + "','" + id + "','" + pwd + "','" + sex + "','" + collage + "','" + power + "','" + "无" + "')";
            SqlConnection con = Utils.SQLTool.GetCon();
            con.Open();
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandText = strsql;
            if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(pwd) && !string.IsNullOrEmpty(name))
                try
                {
                    int count = cmd.ExecuteNonQuery();
                    if (count > 0)
                    {
                        this.NametextBox.Text = "";
                        this.UidtextBox.Text = "";
                        this.PwdtextBox.Text = "";
                        this.SexcomboBox.SelectedIndex = 0;
                        this.CollagecomboBox.SelectedIndex = 0;
                        this.PowercomboBox.SelectedIndex = 0;
                        MessageBox.Show("注册信息成功！");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("注册失败, " + ex.Message);
                }
            else
            {
                MessageBox.Show("信息为空格或空，请重新登入！");
                this.NametextBox.Text = "";
                this.UidtextBox.Text = "";
                this.PwdtextBox.Text = "";
            }
        }

        private void Returnbutton_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
